export function sumValue(array, field) {
    let v = 0;
    array.forEach(function (item){
        const itemVal = item['' + field + ''];
        if (itemVal) {
            v = v + itemVal
        }
    })
    return v
}

export function getJsonArrValueByField(ojb, equalField, equalVal, valueField) {
    console.log(ojb)
    console.log(equalField)
    console.log(equalVal)
    console.log(valueField)
    let v = ''
    ojb.forEach(function (item){
        if (item) {
            const ev = item['' + equalField + ''];
            if (ev && ev === equalVal) {
                const vv = item['' + valueField + ''];
                if (vv) {
                    v = vv
                }
            }
        }
    })
    return v
}

export function doubleLab(v){
    if (!v) {
        return '0';
    }
    let unite =''
    let limit = 1000
    if(v < 1000) {
        limit = 1
    }else if(v >= 1000 && v < 1000000) {
        unite = 'K'
    }else {
        unite = 'M'
        limit = 1000000
    }
    v = v * 1.0/ limit + '';
    if (v.indexOf('.') > 0) {
        let b = v.split('.')[0];
        let f = v.split('.')[1];
        if (f.length > 2) {
            f = f.substring(0, 2)
        }
        return b + '.' + f + unite;
    }
    return v + unite;
}
